<!-- 系统管理员管理端统计页面 -->
<template>
  <div class="">
    <!-- ↓↓↓ 社区人员 ↓↓↓ -->
    <div>
      <div id="cardArea">
        <el-card id="totalCount" class="box-card">
          <div class="info-label"><b>总订单数</b></div>
          <div class="info-label2">
            <svg-icon icon-class="user" class="icon" class-name="card-panel-icon" style="color:#409EFF;font-size:50px;float:left" />
            <span id="totalUser-num" class="num">{{ info.allnumber }}<span style="font-size:15px">笔</span></span>
          </div>
        </el-card>

        <el-card id="contactCount" class="box-card">
          <div class="info-label"><b>分期订单</b></div>
          <div class="info-label2" style="color:#67C23A  ">
            <svg-icon icon-class="table" class="icon" class-name="card-panel-icon" style="font-size:50px;float:left" />
            <span id="contactUser-num" class="num">{{ info.fenqinumber }}<span style="font-size:15px">笔</span></span>
          </div>
        </el-card>
      </div>
      <div id="cardArea">
        <el-card id="feverCount" class="box-card">
          <div class="info-label"><b>直接订单</b></div>
          <div class="info-label2" style="color:#F56C6C">
            <svg-icon icon-class="table" class="icon" class-name="card-panel-icon" style="font-size:50px;float:left" />
            <span id="feverUser-num" class="num">{{ info.zhijienumber }}<span style="font-size:15px">笔</span>  </span>
          </div>
        </el-card>

        <el-card id="hospitalCount" class="box-card">
          <div class="info-label"><b>总收益额</b></div>
          <div class="info-label2" style="color: #E6A23C">
            <svg-icon icon-class="form" class="icon" class-name="card-panel-icon" style="font-size:50px;float:left" />
            <span id="hostipalUser-num" class="num">￥{{ info.allprice }}<span style="font-size:15px">元</span></span>
          </div>
        </el-card>
      </div>
      <!-- <el-card id="isolationCount" class="box-card">
        <div class="info-label"><b>隔离人数</b></div>
        <div class="info-label2" style="color:purple">
          <svg-icon icon-class="user" class="icon" class-name="card-panel-icon" style="font-size:50px;float:left" />
          <span id="isolationUser-num" class="num">{{ info.isolationUser }}<span style="font-size:15px">人</span></span>
        </div>
      </el-card> -->

    </div>

    <div class="pie">
      <el-card class="community-pie-card">
        <div id="myPie1">
          <!-- 123 -->
        </div>
      </el-card>

      <el-card class="community-pie-card">
        <div id="myPie2">
          <!-- 123 -->
        </div>
      </el-card>
    </div>

    <!-- ↑↑↑社区人员↑↑↑ -->
  </div>
</template>

<script>
// 这里可以导入其他文件（比如：组件，工具js，第三方插件js，json文件，图片文件等等）
// 例如：import 《组件名称》 from '《组件路径》';
import { ageStatisticByCampus, eduStatisticByCampus, orderStatisticByCampus } from '@/api/statistic'
import { getCampusByHead } from '@/api/campus'
export default {
  name: 'CampusStatistic',
  // import引入的组件需要注入到对象中才能使用
  components: {},
  data() {
    // 这里存放数据
    return {
      campusId: '',
      campusName: '',
      info: {},
      age: {},
      edu: {}
    }
  },
  // 监听属性 类似于data概念
  computed: {},
  // 监控data中的数据变化
  watch: {},
  // 生命周期 - 创建完成（可以访问当前this实例）
  created() {
    this.getCampus()
    this.fetchData()
  },
  // 生命周期 - 挂载完成（可以访问DOM元素）
  mounted() {
  },
  beforeCreate() {}, // 生命周期 - 创建之前
  beforeMount() {}, // 生命周期 - 挂载之前
  beforeUpdate() {}, // 生命周期 - 更新之前
  updated() {}, // 生命周期 - 更新之后
  beforeDestroy() {}, // 生命周期 - 销毁之前
  destroyed() {}, // 生命周期 - 销毁完成
  activated() {},
  // 方法集合
  methods: {
    getCampus() {
      getCampusByHead().then((resp) => {
        this.campusId = resp.obj.campusId
        this.campusName = resp.obj.campusName
        console.log(this.campusId)
        console.log(this.campusName)
        orderStatisticByCampus(this.campusId).then((resp) => {
          this.info = resp.obj
          this.info.allprice = this.info.allprice / 100
          ageStatisticByCampus(this.campusId).then((res) => {
            this.age = res.obj
            eduStatisticByCampus(this.campusId).then((resp) => {
              this.edu = resp.obj
              this.drawPie()
            })
          })
        })
      })
    },

    drawPie() {
      console.log(this.age)
      console.log(this.edu)
      const pieChart1 = this.$echarts.init(document.getElementById('myPie1'))
      pieChart1.setOption({
        title: {
          text: this.campusName + '用户年龄分布图',
          subtext: '单位（人）',
          left: 'center'
        },
        tooltip: {
          trigger: 'item',
          formatter: '{a} <br/>{b} : {c} 人({d}%)'
        },
        legend: {
          orient: 'vertical',
          left: 'left',
          data: ['幼儿', '儿童', '少年', '青年', '中年', '老年']

        },
        series: [
          {
            name: '占比（人）',
            type: 'pie',
            radius: '55%',
            center: ['50%', '60%'],
            data: [
              { value: this.age.baby, name: '幼儿' },
              { value: this.age.children, name: '儿童' },
              { value: this.age.youngsters, name: '少年' },
              { value: this.age.youth, name: '青年' },
              { value: this.age.mid, name: '中年' },
              { value: this.age.old, name: '老年' }
            ],
            emphasis: {
              itemStyle: {
                shadowBlur: 10,
                shadowOffsetX: 0,
                shadowColor: 'rgba(0, 0, 0, 0.5)'
              }
            }
          }
        ],
        color: ['#409EFF', '#E6A23C', '#F56C6C', '#67C23A', 'purple', 'red']
      })

      const pieChart2 = this.$echarts.init(document.getElementById('myPie2'))
      pieChart2.setOption({
        title: {
          text: this.campusName + '用户学历分布图',
          subtext: '单位（人）',
          left: 'center'
        },
        tooltip: {
          trigger: 'item',
          formatter: '{a} <br/>{b} : {c} 人({d}%)'
        },
        legend: {
          orient: 'vertical',
          left: 'left',
          data: ['学龄前', '小学', '初中', '中专', '高中', '大专', '大学', '硕士', '博士']

        },
        series: [
          {
            name: '占比（人）',
            type: 'pie',
            radius: '55%',
            center: ['50%', '60%'],
            data: [
              { value: this.edu.preschool, name: '学龄前' },
              { value: this.edu.primary, name: '小学' },
              { value: this.edu.junior, name: '初中' },
              { value: this.edu.special, name: '中专' },
              { value: this.edu.senior, name: '高中' },
              { value: this.edu.college, name: '大专' },
              { value: this.edu.undergraduate, name: '大学' },
              { value: this.edu.master, name: '硕士' },
              { value: this.edu.doctor, name: '博士' }
            ],
            emphasis: {
              itemStyle: {
                shadowBlur: 10,
                shadowOffsetX: 0,
                shadowColor: 'rgba(0, 0, 0, 0.5)'
              }
            }
          }
        ],
        color: ['#409EFF', '#E6A23C', '#F56C6C', '#67C23A', 'purple', 'red', 'yellow', 'green', '#EE82EE']
      })
    },
    fetchData() {

    }
  }

  // 如果页面有keep-alive缓存功能，这个函数会触发
}
</script>
<style  scoped>

#cardArea{
    margin: 50px;
    display: flex;
    justify-content: center;

}

 .box-card {
    margin-left: 30px;
    width: 400px;
    height: 180px;
  }

 .info-label{
    line-height: 50px;
    margin-top: 0px;
  }

  .info-label2{
    line-height: 100px;
    margin-top: 0px;
  }

  #totalUser-num{
  color: #409EFF;
  /* font-size: 35px; */
}

.info-label
{
  color: #606266;
  /* text-align: right; */
  /* font-size:35px; */
}

.num{
  float:right;
  text-align: right;
  font-size: 35px;
  margin-right: 10px;
  /* margin-left: 60%; */
}

.icon{
  margin-top: 15px;
  text-align: left;
}

.community-pie-card{

  /* width: 95%; */
  /* width: 57%; */
  float:right;
  margin-right: 5%;

}
.pie{
    display: flex;
    justify-content: center;
    margin-left: 3%;
    width: 100%;
}

#myPie1{
  width: 700px;
  height: 530px;
}

#myPie2{
  width: 700px;
  height: 530px;
}
</style>
